namespace SilverSea.Untilities
{
    using System;

    public static class DateTimeUntils
    {
        public static long DateDiff(DateInterval interval, DateTime date1, DateTime date2)
        {
            TimeSpan span;
            span = span = (TimeSpan) (date2 - date1);
            switch (interval)
            {
                case DateInterval.Year:
                    return (long) (date2.Year - date1.Year);

                case DateInterval.Month:
                    return (long) ((date2.Month - date1.Month) + (12 * (date2.Year - date1.Year)));

                case DateInterval.Weekday:
                    return (smethod_0(span.TotalDays) / 7L);

                case DateInterval.Day:
                    return smethod_0(span.TotalDays);

                case DateInterval.Hour:
                    return smethod_0(span.TotalHours);

                case DateInterval.Minute:
                    return smethod_0(span.TotalMinutes);
            }
            return smethod_0(span.TotalSeconds);
        }

        public static int GetDayOfWeekInNumber(DateTime dates)
        {
            switch (dates.DayOfWeek)
            {
                case DayOfWeek.Sunday:
                    return 1;

                case DayOfWeek.Monday:
                    return 2;

                case DayOfWeek.Tuesday:
                    return 3;

                case DayOfWeek.Wednesday:
                    return 4;

                case DayOfWeek.Thursday:
                    return 5;

                case DayOfWeek.Friday:
                    return 6;

                case DayOfWeek.Saturday:
                    return 7;
            }
            return -1;
        }

        public static int GetDayOfWeekInNumber1(DateTime dates)
        {
            switch (dates.DayOfWeek)
            {
                case DayOfWeek.Sunday:
                    return 7;

                case DayOfWeek.Monday:
                    return 1;

                case DayOfWeek.Tuesday:
                    return 2;

                case DayOfWeek.Wednesday:
                    return 3;

                case DayOfWeek.Thursday:
                    return 4;

                case DayOfWeek.Friday:
                    return 5;

                case DayOfWeek.Saturday:
                    return 6;
            }
            return -1;
        }

        public static int GetDayOfWeekInNumber2(DateTime dates)
        {
            switch (dates.DayOfWeek)
            {
                case DayOfWeek.Sunday:
                    return 0;

                case DayOfWeek.Monday:
                    return 1;

                case DayOfWeek.Tuesday:
                    return 2;

                case DayOfWeek.Wednesday:
                    return 3;

                case DayOfWeek.Thursday:
                    return 4;

                case DayOfWeek.Friday:
                    return 5;

                case DayOfWeek.Saturday:
                    return 6;
            }
            return -1;
        }

        public static int GetDayOfWeekInNumberDS3000(DateTime dates)
        {
            switch (dates.DayOfWeek)
            {
                case DayOfWeek.Sunday:
                    return 0;

                case DayOfWeek.Monday:
                    return 0x20;

                case DayOfWeek.Tuesday:
                    return 0x40;

                case DayOfWeek.Wednesday:
                    return 0x60;

                case DayOfWeek.Thursday:
                    return 0x80;

                case DayOfWeek.Friday:
                    return 160;

                case DayOfWeek.Saturday:
                    return 0xc0;
            }
            return 0;
        }

        public static int GetTimeNumber(string timeString)
        {
            return ((Convert.ToInt32(timeString.Substring(0, 2)) * 60) + Convert.ToInt32(timeString.Substring(3, 2)));
        }

        public static string GetTimeString(long timeNumber)
        {
            long num = timeNumber / 60L;
            long num2 = timeNumber - (num * 60L);
            return (num.ToString("00") + ":" + num2.ToString("00"));
        }

        private static long smethod_0(double double_0)
        {
            if (double_0 >= 0.0)
            {
                return (long) Math.Floor(double_0);
            }
            return (long) Math.Ceiling(double_0);
        }
    }
}

